package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.Idea;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class IdeaDao {
	private DBHelp<Idea> db = new DBHelp<Idea>();
	
	public List<Idea> findByProjectId(int projectid){
		String sql="SELECT id,content,`name`,createtime,projectid,title,userid FROM	t_idea WHERE projectid=?";
		return db.executeQueryForList(sql, new IdeaRowMapper(), projectid);
	}
	
	
	
	
	private class IdeaRowMapper implements RowMapper<Idea>{

		public Idea mapperRow(ResultSet rs) throws SQLException {
			// TODO Auto-generated method stub
			Idea i = new Idea();
			i.setContent(rs.getString("content"));
			i.setCreatetime(rs.getString("createtime"));
			i.setId(rs.getInt("id"));
			i.setName(rs.getString("name"));
			i.setProjectID(rs.getInt("projectID"));
			i.setTitle(rs.getString("title"));
			i.setUserID(rs.getInt("userID"));
			return i;
		}
		
	}
}
